﻿using Loki.Data;
using Luna.Data.Mappers;

namespace Luna.Data.Accounting.Mappers
{
    public class AccountDataMapper : LunaEntityMapper<AccountData, IAccountData>
    {
        public const string COL_BANK = "Bank";
        public const string COL_NAME = "Name";
        public const string COL_NUMBER = "Number";
        public const string COL_INITIAL_AMOUNT = "InitialAmount";
        public const string COL_START_DATE = "StartDate";

        protected override void LoadCoreData(IAccountData P_Entity, System.Data.IDataRecord P_Record)
        {
            P_Entity.Bank = P_Record.GetString(COL_BANK);
            P_Entity.Name = P_Record.GetString(COL_NAME);
            P_Entity.Number = P_Record.GetString(COL_NUMBER);
            P_Entity.InitialAmount = P_Record.GetDecimal(COL_INITIAL_AMOUNT);
            P_Entity.StartDate = P_Record.GetDate(COL_START_DATE);
        }

        protected override void MapSaveParameters(IDatabaseCommand P_Command, IAccountData P_Entity)
        {
            P_Command.AddParameter(COL_NAME, P_Entity.Name);
            P_Command.AddParameter(COL_BANK, P_Entity.Bank);
            P_Command.AddParameter(COL_NUMBER, P_Entity.Number);
            P_Command.AddParameter(COL_INITIAL_AMOUNT, P_Entity.InitialAmount);
            P_Command.AddParameter(COL_START_DATE, P_Entity.StartDate);
            P_Command.AddParameter(COL_ID, P_Entity.PK);
        }
    }
}
